<!DOCTYPE html>
<html>
<head>
<title>角色添加修改</title>
<meta name="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript" charset="UTF-8" src="../../../easyui/jquery.min.js"></script>
<link rel="stylesheet" id="easyuiTheme" href="../../../easyui/themes/default/easyui.css" type="text/css"></link>
<link rel="stylesheet" id="easyuiTheme" href="../../../easyui/themes/icon.css" type="text/css"></link>
<script type="text/javascript" src="../../../easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../../../easyui/locale/easyui-lang-zh_CN.js"></script>

<link rel="stylesheet" href="../../../style/syExtIcon.css" type="text/css"></link>
<link rel="stylesheet" href="../../../style/syExtCss.css" type="text/css"></link>
<script type="text/javascript" src="../../../js/ExtEasyui.js"></script>
<script type="text/javascript" src="../../../js/Extjs.js"></script>
<script type="text/javascript">
var roleTree;
$(function(){
	roleTree = $('#tree_role').tree({
		method: 'get',
		url : '/role/getAll',
		checkbox : true,
		formatter : function(node) {
			return node.name;
		},
		onLoadSuccess : function(node, data) {
			var roleIds = $("#role_ids").val();
			var ids = $.stringToList(roleIds);
			if (ids.length > 0) {
				for (var i = 0; i < ids.length; i++) {
					if (roleTree.tree('find', ids[i])) {
						roleTree.tree('check', roleTree.tree('find', ids[i]).target);
					}
				}
			}
		}
	});
});

var userrole_submitForm = function(dialog, userDataGrid, p) {
	var nodes = roleTree.tree('getChecked', [ 'checked', 'indeterminate' ]);
	var ids = [];
	for (var i = 0; i < nodes.length; i++) {
		ids.push(nodes[i].id);
	}
	$("#role_ids").val(ids.join(','));
	
	$.post('/user/role', $("#user_role_addForm").serialize(), function(j) {
		if (j.success) {
			userDataGrid.datagrid('reload');
			dialog.dialog('destroy');
		}
		p.messager.show({
			title : '提示',
			msg : j.msg,
			timeout : 5000,
			showType : 'slide'
		});
	}, 'json').fail(function(response){
		// console.log("---------------------error---" + response.status);
		if(response.status == 401){			
			p.messager.show({
				title : '提示',
				msg : "无此操作权限",
				timeout : 5000,
				showType : 'slide'
			});
		}
	});
};
</script>
</head>

<body>
<form id="user_role_addForm" method="post">
<input type="hidden" id="user_id" name="userId" value="{user.id}"/>
<input type="hidden" id="role_ids" name="roleIds" value="{user.roleIds ?: ''}"/>
	<fieldset>
		<legend>用户授权</legend>
		<ul id="tree_role"></ul>
	</fieldset>
</form>
</body>
</html>